﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using System.Configuration;

namespace TCDC_System.Register
{
    public partial class Register4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SessionValue();
            }
        }

        private void SessionValue()
        {
            txtEmail.Text = Session["email"].ToString();
            txtPassword.Text = Session["password"].ToString();
            txtCampaign.Text = Session["campaign"].ToString();
            txtReference.Text = "TEST001";

        }

        protected void btnBack_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Register3.aspx");
        }

        protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
        {
            tcdc_mst_user objUser = new tcdc_mst_user();
            tcdc_trn_user_campaign objCampaign = new tcdc_trn_user_campaign();

            objUser.strConn = ConfigurationSettings.AppSettings["ConnString"];
            objCampaign.strConn = ConfigurationSettings.AppSettings["ConnString"];

            objUser.username = Session["email"].ToString();
            objUser.user_type_id = 1;
            objUser.fname_th = Session["first_name_th"].ToString();
            objUser.fname_en = Session["first_name_en"].ToString();
            objUser.lname_th = Session["last_name_th"].ToString();
            objUser.lname_en = Session["last_name_en"].ToString();
            objUser.id_card = Session["id_card"].ToString();

            int user_id = objUser.insertData(objUser);

            objCampaign.user_id = user_id;
            objCampaign.campaign_id = Convert.ToInt32(Session["campaign"].ToString());
            objCampaign.status = "pending";
            objCampaign.reference_no = "TEST0001";

            objCampaign.insertData(objCampaign);


            Session.Clear();

            Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('Record Success');", true);
            Response.Redirect("Register1.aspx");
        }
    }
}